#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
void _mersort(int* a, int* tem, int left, int right)
{
	if (left >= right)
	{
		return;
	}
	int mid = left + (right - left) / 2;
	_mersort(a, tem, left, mid);
	_mersort(a, tem, mid + 1, right);
	
	int begin1 = left;
	int end1 = mid;
	int begin2 = mid+1;
	int end2 = right;
	int i = left;
	while (begin1 <= end1 && begin2 <= end2)
	{
		if (a[begin1] <= a[begin2])
		{
			tem[i++] = a[begin1++];
		}
		else
		{
			tem[i++] = a[begin2++];
		}

	}
	while (begin1 <= end1)
	{
		tem[i++] = a[begin1++];
	}
	while (begin2 <= end2)
	{
		tem[i++] = a[begin2++];
	}
	memcpy(a + left, tem + left, 4*(right - left + 1));
}
void mersort(int* a, int n)
{
	int* tem = new int[n];
	_mersort(a, tem, 0, n - 1);
}
int main()
{
	int a[] = { 9,8,63,1321,34 };
	mersort(a, sizeof(a) / sizeof(a[0]));
	for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
	{
		cout << a[i]<<" ";
	}
	return 0;
}
